package com.tledu.service.impl;

import com.tledu.core.BusinessException;
import com.tledu.domain.Book;
import com.tledu.mapper.BookMapper;
import com.tledu.service.IBookService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author cyrus
 */
@Service
@AllArgsConstructor
public class BookServiceImpl implements IBookService {

    private final BookMapper bookMapper;

    @Override
    public int insert(Book book) {
        if (book.getName() == null) {
            throw new BusinessException(400, "插入图书失败，缺少name的参数");
        }
        return bookMapper.insert(book);
    }

    @Override
    public int update(Book book) {
        return bookMapper.update(book);
    }

    @Override
    public int delete(int id) {
        return bookMapper.delete(id);
    }

    @Override
    public Book selectById(int id) {
        return bookMapper.selectById(id);
    }

    @Override
    public List<Book> selectList(Book book) {
        return bookMapper.selectList(book);
    }
}
